<?php

namespace User\Form;

use Zend\Form\Form;

class FormRegister extends Form {

    private $captcha;

    public function __construct() {

        parent::__construct();

//        $this->captcha = new \Zend\Captcha\Figlet();
//        $this->captcha->setWordlen(7);
//        $this->captcha->setTimeout(300);
//        $this->captcha->setName('captcha');
//        $this->captcha->setMessage('Mã an toàn không đúng');

        $this->captcha = new \Zend\Captcha\Image(array(
            'expiration' => '300',
            'wordlen' => '7',
            'font' => './public/upload/images/captcha/arialbd.ttf',
            'fontSize' => '20',
            'imgDir' => './public/upload/images/captcha',
            'imgUrl' => '/upload/images/captcha',
            'messages' => array('badCaptcha' => 'Mã an toàn không đúng')
        ));
        $this->captcha->setName('register-captcha');


        $this->setAttribute('name', 'frmUserRegister');
        $this->setAttribute('method', 'post');

        //for user email
        $this->add(array(
            'name' => 'member_email',
            'type' => 'text',
            'attributes' => array(
                'class' => 'form-control'
            ),
            'options' => array(
                'label' => 'Email',
                'label_attributes' => array(
                    'class' => 'col-sm-2 control-label'
                )
            )
        ));

        //for user password
        $this->add(array(
            'name' => 'member_password',
            'type' => 'password',
            'attributes' => array(
                'class' => 'form-control'
            ),
            'options' => array(
                'label' => 'Mật khẩu',
                'label_attributes' => array(
                    'class' => 'col-sm-2 control-label'
                )
            )
        ));

        //for retype password
        $this->add(array(
            'name' => 'retype_password',
            'type' => 'password',
            'attributes' => array(
                'class' => 'form-control'
            ),
            'options' => array(
                'label' => 'Nhập lại mật khẩu',
                'label_attributes' => array(
                    'class' => 'col-sm-2 control-label'
                )
            )
        ));

        $this->add(array(
            'name' => 'captcha',
            'type' => 'Zend\Form\Element\Captcha',
            'attributes' => array(
                'class' => 'form-control'
            ),
            'options' => array(
                'label' => 'Mã an toàn',
                'label_attributes' => array(
                    'class' => 'col-sm-2 control-label'
                ),
                'captcha' => $this->captcha
            )
        ));

        //for register button
        $this->add(array(
            'name' => 'register',
            'type' => 'submit',
            'attributes' => array(
                'value' => 'Đăng ký',
                'class' => 'btn btn-default'
            )
        ));
    }

}
